import { Component, OnInit } from '@angular/core';
import { NewsService } from '../../service/news.service';
import { Router, ActivatedRoute } from '@angular/router';
import { News } from '../../model/news';

@Component({
  selector: 'app-edit',
  templateUrl: './edit.component.html',
  styleUrls: ['./edit.component.css']
})
export class EditComponent implements OnInit {
     parm:String ;
     news:News;
     config:any;
  constructor(
    private newsservice:NewsService,
    private router:Router
    ,private routeinfo:ActivatedRoute

  ) { 
       this.parm=this.routeinfo.snapshot.params["id"];

  }


  ngOnInit() {
    
    this.news=new News();

  }

   goBack(){

     this.router.navigate(['managelist']);
   }
   save(){
     console.dir(this.news);

     this.newsservice.addNews(this.news)
        .then((flag:boolean)=>{
          if(flag==true){
            this.goBack();
          }
          else{
            alert("数据异常，请刷新后重试");
          }
      

     })

    }
}
